#include <iostream>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <set>
#include <unordered_set>
#define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
priority_queue<int,vector<int>,greater<int> >q;
int main()
{
	int n,k;
	cin>>n>>k;
	for(int i=0;i<k;i++)
	{
		int t;
		cin>>t;
		q.push(t);
	}
	for(int i=k;i<n;i++)
	{
		int t;
		cout<<q.top()<<endl;;
		cin>>t;
		q.push(t);
		q.pop();
	}
	cout<<q.top()<<endl;;

	return 0;
}

